package com.example.zollerfileparsingdemo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tools.PathUtil;

import javax.annotation.PostConstruct;
import java.nio.file.Paths;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@SpringBootApplication
public class ZollerFileParsingDemoApplication {
        private final static int AVALIABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
    /*新建线程池*/

    private final static ThreadPoolExecutor POOL_EXECUTOR = new ThreadPoolExecutor(AVALIABLE_PROCESSORS,
            AVALIABLE_PROCESSORS*2,
            1,
            TimeUnit.MINUTES,
            new LinkedBlockingDeque<>(5),
            new ThreadPoolExecutor.DiscardPolicy()
    );
    @PostConstruct
    public void startServer() throws Exception {
//        long start = System.currentTimeMillis();

        /*执行另一个任务*/
        POOL_EXECUTOR.execute(()->{
            try {
                /*启动监听服务*/
//        /*监听传输文件*/
                PathUtil.listenFiles(Paths.get("e:/path"));

            } catch (Throwable throwable){
                log.error("监听传输文件错误->",throwable);
            }

        });

    }

    public static void main(String[] args) {
        SpringApplication.run(ZollerFileParsingDemoApplication.class, args);
    }

}
